//
//  CourseModel.m
//  MetenEnglish
//
//  Created by Hsn on 14/11/19.
//  Copyright (c) 2014年 Shenzhen Securities Information Co., Ltd. All rights reserved.
//

#import "CourseModel.h"

@implementation CourseModel

- (instancetype)initWithCourseName:(NSString *)name
                              time:(NSString *)time
                           teacher:(NSString *)teacher
                           address:(NSString *)address
                      studentCount:(NSString *)studentCount
                          courseId:(NSString *)courseId
{
    self = [super init];
    if (self) {
        _name = [name stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];
        _time = [time stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];
        _teacher = [teacher stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];
        _address = [address stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];
        _address = [_address stringByReplacingOccurrencesOfString:@"\n" withString:@""];
        _address = [_address stringByReplacingOccurrencesOfString:@"                                " withString:@""];
        _studentCount = [studentCount stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];
        _courseId = courseId;
    }
    return self;
}

- (COURSE_STATUS)getCourseStatus {
    
    COURSE_STATUS status = COURSE_NORMAL;
    
    if ([self.status isEqualToString:@"订课"]) {
        status = COURSE_RESERVE;
    }else if ([self.status isEqualToString:@"排队"]) {
        status = COURSE_STANDBY;
    }else if ([self.status isEqualToString:@"订满"]) {
        status = COURSE_FULL;
    }else if ([self.status isEqualToString:@"已订"]) {
        status = COURSE_RESERVED;
    }else if ([self.status isEqualToString:@"已订其它"]) {
        status = COURSE_RESERVEDOTHER;
    }
    else if ([self.status isEqualToString:@"取消排队"]) {
        status = COURSE_CANCEL_QUEUE;
    }
    
    return status;
}

- (NSString *)getCourseId {
    NSRange rangeFront = [self.courseId rangeOfString:@"("];
    NSRange rangeBehind = [self.courseId rangeOfString:@")"];
    if (rangeFront.location != NSNotFound) {
        self.courseId = [self.courseId substringWithRange:NSMakeRange(rangeFront.location + 1,
                                                                      rangeBehind.location - rangeFront.location - 1)];
    }
    return self.courseId;
}

- (void)setCourseCategoryWithString:(NSString *)courseCategory {
    if (!courseCategory) {
        return;
    }
    if ([courseCategory isEqualToString:@"101"]) {
        _courseCategory = COURSE_MAJOR;
    }else if ([courseCategory isEqualToString:@"102"]) {
        _courseCategory = COURSE_SC;
    }else if ([courseCategory isEqualToString:@"103"]) {
        _courseCategory = COURSE_ISHOW;
    }else {
        _courseCategory = COURSE_OTHER;
    }
}

@end
